<?php
require_once 'LoanMasters.php';

class Applications extends LoanMasters
{
    
    
    protected function _setGridMetadata()
    {
        parent::_setGridMetadata();
        $this->_gridMetadata['title'] = $this->translate("Loan applications");
        $this->_gridMetadata['onClick'] = 'loan.application.view';
        return $this;
    }
    
    public function save($data)
    {
        $l = $data['Loan'];
        unset($data['Loan']);
        
        $this->getDefaultAdapter()->beginTransaction();       
        try {
            $loanMasterId = $this->insert($data);
            $loans = new Loans(array('name' => 'loans')); 
            foreach($l as $d) {
                $l[$d['ClientId']]['LoanMasterId'] = $loanMasterId;
                $loans->insert($l[$d['ClientId']]);
            }
        } catch (Zend_Exception $e) {
            $this->getDefaultAdapter()->rollBack();                   
            throw new Exception($e->getMessage());
            return;
        }  
        $this->getDefaultAdapter()->commit();
        return $loanMasterId;
    }
    
    
}